<?php

define('USE_MAIL', false);
define('USE_SMTP', true);

define('SMTP_HOST', 'smtp.ngs.ru');
define('SMTP_LOGIN', 'otmopo3ok');
define('SMTP_PASSWORD', 'cwerj');
define('ADMIN_EMAIL', 'otmopo3ok@ngs.ru');

class EmailSenderComponent extends Object {

	var $components = array('Email', 'Session');

	function startup(&$controller) {
		$this->Controller = &$controller;
		
		if (USE_MAIL) {
			$this->Email->delivery = 'mail';
		}
		if (USE_SMTP) {
			$this->Email->delivery = 'smtp';
			$this->Email->smtpOptions = array('port' => 25,
							  'host' => SMTP_HOST,
							  'username' => SMTP_LOGIN,
							  'password' => SMTP_PASSWORD,
							  'timeout' => 30);
		}
	}
	
	function registration($data) {
		$this->Email->to = $data['User']['email'];
		$this->Email->from = ADMIN_EMAIL;
		$this->Email->replyTo = ADMIN_EMAIL;
		$this->Email->subject = "Registration";
		$this->Email->template = "registration";
		$this->Email->sendAs = "both";
		$this->Email->Controller->set("user", $data);
		if ($this->Email->send())
			return true;
		return false;
	}
	
	function password($data, $new_password) {
		$this->Email->to = $data['User']['email'];
		$this->Email->from = ADMIN_EMAIL;
		$this->Email->replyTo = ADMIN_EMAIL;
		$this->Email->subject = "Restore password";
		$this->Email->template = "password";
		$this->Email->sendAs = "both";
		$this->Email->Controller->set("user", $data);
		$this->Email->Controller->set("new_password", $new_password);
		if ($this->Email->send())
			return true;
		return false;
	}
}
?>
